﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="MicrosoftAjaxSample._Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>How to call CSharp function in Ajax | Microsoft Ajax Sample</title>

    <script type="text/javascript">

        function getServerTime() {
            /// <summary>
            /// Call ServerTime web method via ajax request
            /// </summary>
            MicrosoftAjaxSample.AjaxServer.ServerTime(OnComplete, OnError);
        }

        function OnComplete(result) {
            /// <summary>
            /// Display server time when success
            /// </summary>
            document.getElementById("ServerTimeResponse").innerHTML = result;
        }
        
        function OnError(result) {
            /// <summary>
            /// show error message when there is an error
            /// </summary>
            alert("Error: " + result.get_message());
        }

    </script>

</head>
<body>
    <form id="ServerTimeForm" runat="server">
    <asp:ScriptManager ID="ServerTimeScriptManager" runat="server">
        <Services>
            <asp:ServiceReference Path="~/AjaxServer.asmx" />
        </Services>
    </asp:ScriptManager>
    <div>
        <input onclick="getServerTime();" id="ServerTimeButton" type="button" value="Get Server Time" />
        <div id="ServerTimeResponse" runat="server">
        </div>
    </div>
    </form>
</body>
</html>
